package com.liangdemo.web.test.demo;

import lombok.Data;

/**
 * equals（）方法
 *
 * @author: LiangErLe
 * @date: 2022/8/18
 **/
public class EqualsDemo {
    public static void main(String[] args) {
        EqualsDemo equalsDemo = new EqualsDemo();
        equalsDemo.test();
    }

    public void test() {
        User user1 = new User();
        User user2 = new User();
        //判断两个对象是否相等
        System.out.println(user1.equals(user2));
        System.out.println(user1 == user2);


        user1.setName("张三");
        user2.setName("张三");
        System.out.println(user1.getName() == user2.getName());
        System.out.println(user1.getName().equals(user2.getName()));
    }

    public  void  test1(){
        String str1="张三";
        String st2="张三";
        System.out.println(str1 == st2);
        System.out.println(st2.equals(str1));
    }

    @Data
    class User {
        private String name;
    }
}
